import { Component, OnInit, ViewChild } from '@angular/core';
import { ActivatedRoute, NavigationExtras, Router } from '@angular/router';
import { Location } from '@angular/common';
// 服务
import { LoadingAnimateService } from '../../../common/loading';
import { AlertService } from '../../../common/alert';
import { BackComponent } from '../../../common/back.component';
import { EventListenService } from './eventlisten.service';

import { EventListen } from './eventlisten';

@Component({
    moduleId: module.id,
    templateUrl: 'eventlisten.add.component.html',
    providers: [EventListenService]
})
export class EventlistenAddComponent implements OnInit {

    data: EventListen

    constructor(
        private router: Router,
        private route: ActivatedRoute,
        private loadingService: LoadingAnimateService,
        private eventListenService: EventListenService,
        private alert: AlertService,
        private location: Location
    ) { }

    ngOnInit(): void {
        this.data = new EventListen()
        this.data.from="manager"
    }
    onSubmit(): void {
        this.add();
    }
    add(): void {
        this.loadingService.setValue(true);
        this.eventListenService.add(this.data).then(
            res => {
                this.loadingService.setValue(false);
                if (res.ok) {
                    this.alert.showBlock('保存成功').subscribe( ()=> {
                        this.location.back();
                    });
                    
                } else {
                    this.alert.show('保存失败');
                }
            }
        ).catch(res=>{
            console.log(res);
             this.alert.show("新增失败:" + res);
        });
    }


}
